# Maintainer: Ricky Wu <rickleaf.wu@gmail.com>
# Contributor: ImperatorS79 <fevrier.simon@gmail.com>
# Contributoor: Ray Donnelly <mingw.android@gmail.com>

_realname=luarocks
pkgbase=mingw-w64-lua-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-lua-${_realname}")
pkgver=3.7.0
pkgrel=1
pkgdesc="the package manager for Lua modules (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
install=${_realname}-${MSYSTEM}.install
url="https://luarocks.org"
license=("MIT")
depends=("${MINGW_PACKAGE_PREFIX}-lua"
		 "unzip"
	     "zip")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
options=('staticlibs' 'strip')
source=("https://luarocks.org/releases/${_realname}-${pkgver}.tar.gz"
		"0001-luarocks_msys2_mingw_w64.patch")
sha256sums=('9255d97fee95cec5b54fc6ac718b11bf5029e45bed7873e053314919cd448551'
            '944f5a3d831576fc7994ab7aa459b68fe7ada86ba440cc76fbd1ea5b3f2682db')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/0001-luarocks_msys2_mingw_w64.patch
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ./configure --prefix=${MINGW_PREFIX} --lua-version=5.4 --with-lua-interpreter=lua.exe
  make ./build/luarocks ./build/luarocks-admin ./build/config-5.4.lua
  make LUA_VERSION=5.1 LUA_INTERPRETER=lua5.1.exe LUA_INCDIR=${MINGW_PREFIX}/include/lua5.1 ./build/config-5.1.lua
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
  make DESTDIR="$pkgdir" LUA_VERSION=5.1 install-config
}
